//
//  UIFooterView.m
//  Assistant
//
//  Created by Hunk on 12-3-1.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "UIFooterView.h"
#import <QuartzCore/QuartzCore.h>

#define WIDTH_BUTTON  (300.0)
#define HEIGHT_BUTTON (42.0)

@implementation UIFooterView
@synthesize delegate = _delegate;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) 
    {
        UIButton* deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
        CGFloat fX = (self.bounds.size.width - WIDTH_BUTTON) / 2;
        CGFloat fY = (self.bounds.size.height - HEIGHT_BUTTON);
        [deleteButton setFrame:CGRectMake(fX, fY, WIDTH_BUTTON, HEIGHT_BUTTON)];
        [deleteButton setBackgroundColor:[UIColor clearColor]];
        deleteButton.layer.cornerRadius = CORNERRADIUS;
        deleteButton.layer.masksToBounds = YES;    
        [deleteButton setBackgroundImage:[UIImage imageNamed:@"redBg.png"] forState:UIControlStateNormal];
        [deleteButton setBackgroundImage:[UIImage imageNamed:@"redBg.png"] forState:UIControlStateSelected];
        [deleteButton setTitle:NSLocalizedString(@"删除群组", nil) forState:UIControlStateNormal];
        [deleteButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [deleteButton.titleLabel setFont:[UIFont boldSystemFontOfSize:18]];
        [deleteButton addTarget:self 
                         action:@selector(deleteButtonHandle:) 
               forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:deleteButton];
    }
    return self;
}

- (void)setDelegate:(id<UIFooterViewDelegate>)delegate
{
    if(_delegate != delegate)
    {
        [_delegate release];
        
        _delegate = [delegate retain];
    }
}

- (void)deleteButtonHandle:(id)sender
{
    if(_delegate && [_delegate respondsToSelector:@selector(didSelected:)])
    {
        [_delegate didSelected:self];
    }
}

- (void)dealloc
{
    SAFE_RELEASE(_delegate)
    
    [super dealloc];
}

@end
